package logic

import (
	"context"
	"go.uber.org/zap"
	"smart-health-platforms/pkg"
	"user_srv/internal/dao"
	"user_srv/internal/svc"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddressListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddressListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddressListLogic {
	return &AddressListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 地址列表
func (l *AddressListLogic) AddressList(in *user.AddressListRequest) (*user.AddressListResponse, error) {
	list, err := dao.AddressList(int(in.UserId))
	var respList []*user.ListAddress
	for _, addr := range list {
		respList = append(respList, &user.ListAddress{
			Name:    addr.Name,
			Address: addr.Address,
			Mobile:  addr.Mobile,
			Status:  int64(addr.Status),
			UserId:  int64(addr.UserId),
		})
	}
	if err != nil {
		pkg.Error("列表展示失败", zap.Error(err))
		return nil, err
	}

	return &user.AddressListResponse{List: respList}, nil
}
